
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>菜品管理</title>
    <style>
        .dish-table { width: 80%; margin: 20px auto; border-collapse: collapse; }
        .dish-table th, .dish-table td { border: 1px solid #ddd; padding: 8px; text-align: center; }
        .delete-btn { color: red; cursor: pointer; }
    </style>
    <script>
        function confirmDelete(dishId, dishName) {
            return confirm("确定要删除菜品 '" + dishName + "' 吗？");
        }
    </script>
</head>
<body>
<%@ include file="adminMenu.jsp" %>

<h2 style="text-align:center;">菜品管理列表</h2>
<c:if test="${not empty param.status}">
    <div style="color:green; text-align:center;">删除成功！</div>
</c:if>

<table class="dish-table">
    <tr>
        <th>菜品ID</th>
        <th>菜品名称</th>
        <th>价格</th>
        <th>图片路径</th>
        <th>操作</th>
    </tr>
    <c:forEach items="${dishes}" var="dish">
        <tr>
            <td>${dish.id}</td>
            <td>${dish.name}</td>
            <td>￥<fmt:formatNumber value="${dish.price}" pattern="#.00"/></td>
            <td>${dish.image}</td>
            <td>
                <form action="DeleteDishServlet" method="post"
                      onsubmit="return confirmDelete(${dish.id}, '${dish.name}')">
                    <input type="hidden" name="dishId" value="${dish.id}">
                    <button type="submit" class="delete-btn">删除</button>
                </form>
            </td>
        </tr>
    </c:forEach>
</table>

<div style="text-align:center; margin-top:20px;">
    <a href="admin.jsp">返回管理首页</a>
</div>
</body>
</html>
